安装cocopods (网上查找教程)
在GitHub上创建仓库,
将仓库clone到本地
$ git clone https://github.com/YourName/REPO_NAME.git
在仓库根目录创建Xcode工程
在Xcode中编写相关代码
在项目根目录创建 XXX.podspec 文件 (XXX为库名)
$ pod spec create XXX (XXX:库名)
编辑podspec文件
Pod::Spec.new do |s| s.name = "SpeedyKit" # 项目名称 s.version = "0.0.1" # 版本号 与 你仓库的 标签号 对应 s.license = "MIT" # 开源证书 s.summary = "A delightful TextField of SpeedyKit" # 项目简介 s.homepage = "https://github.com/XFNicar/SpeedyKit" # 你的主页 s.source = { :git => "https://github.com/XFNicar/SpeedyKit.git", :tag => "#{s.version}" }#你的仓库地址,不能用SSH地址 s.source_files = "SpeedyKit/SpeedyKit/UIKit/**/*.{h,m}", "SpeedyKit/SpeedyKit/Foundation/**/*.{h,m}" # 你代码的位置,以上路径以.podspec文件所在位置为根目录,一直到实际代码所在位置为止,说明如下 # SpeedyKit/SpeedyKit/UIKit/**/*.{h,m} # SpeedyKit/SpeedyKit/Foundation/**/*.{h,m} # 表示 SpeedyKit/SpeedyKit/UIKit/ 和 SpeedyKit/SpeedyKit/Foundation/ 文件夹下所有文件夹及其目录下的.h和.m文件 s.requires_arc = true # 是否启用ARC s.platform = :ios, "7.0" #平台及支持的最低版本 s.frameworks = "UIKit", "Foundation" #支持的框架 # s.dependency = "AFNetworking" # 依赖库 (如有) # User s.author = { "XFNicar" => "xuejingwen25@163.com" } # 作者信息 s.social_media_url = "https://XFNicar.github.io" # 个人主页 end
验证podspec文件
$ pod lib lint 验证通过即可开始提交代码到GitHub
提交代码到GitHub
$ git add . $ git commit -m "提交信息" $ git push origin master
给仓库打标签
标签相当于将你的仓库的一个压缩包,用于稳定存储当前版本。 标签号与你在 s.version = "1.0.0"的版本号一致 1.0.0 $ git tag -a XXX -m "发布XXX版本" $ git push origin --tags
发布 .podspec
$ pod trunk push SpeedyKit.podspec
看到如下提示则表示发布成功了
-------------------------------------------------------------------------------- 🎉 Congrats 🚀 SpeedyKit (0.0.1) successfully published 📅 November 27th, 10:13 🌎 https://cocoapods.org/pods/SpeedyKit 👍 Tell your friends! --------------------------------------------------------------------------------
常见问题
校验 .podspec 的时候报如下错误
$ pod search speedykit [!] ConvenientKit did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it). You can use the `--no-clean` option to inspect any issue.
该情况一般是因为没有创建LICENSE 文件所引起的,添加LICENSE 文件即可,也可以使用
--allow-warnings
命令消除报错发布.podspec 的时候提示如下信息
$ pod trunk push SpeedyKit.podspec [!] You (xxxx@gmail.com) are not allowed to push new versions for this pod. The owners of this pod are xxxx@gmail.com.
抱歉你的库名已经被占用,请换其他的吧
搜索不到库
$ pod search speedykit [!] Unable to find a pod with name, author, summary, or description matching `speedykit`
解决办法 :删掉本地的搜索目录文件即可
$ rm ~/Library/Caches/CocoaPods/search_index.json